export default function(){
    return {
        data() {
            return {
                paramsArr: [],
                paramsStr: "",
            }
        },
        methods: {
            handleChange(paramsObj) {
                this.dialogFormVisible = true;
                this.paramsStr = paramsObj;
                this.paramsArr = this.jsonToArr(JSON.parse(paramsObj ? paramsObj : '{"":""}'));
            },
            jsonToArr(paramsObj) {
              let tempArr = [];
              for (let k in paramsObj) {
                tempArr.push({ key: k, value: paramsObj[k] });
              }
              return tempArr;
            },
            arrToJson(arr) {
              let tempObj = {};
              arr.forEach(item => {
                tempObj[item.key] = item.value;
              });
              this.isJson = true;  //关闭是否JSON提示
              return JSON.stringify(tempObj);
            },
            addParams() {
              this.paramsArr.push({ key: "", value: "" });
            },
            handleKey(item, index) {
              this.paramsArr.every((paramItem, paramIndex) => {
                if (paramIndex == index) {
                  paramItem = item;
                  this.paramsStr = this.arrToJson(this.paramsArr);
                  return false;
                }
                return true;
              });
            },
            removeParams(index) {
              this.paramsArr.splice(index, 1);
              this.paramsStr = this.arrToJson(this.paramsArr);
            },
            submitParams() {
              this.dialogFormVisible = false;
              this.record.paramJson = this.paramsStr;
            },
            closeDialog() {
              this.paramsArr = [];
            },
        }
    }
}